package com.example.yjhuser.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.yjhuser.entity.Comment;
import com.example.yjhuser.entity.PersonCommentDTO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommentMapper extends BaseMapper<Comment> {

    @Select("select  u1.name,u2.`name` pname ,u1.image,cm.* from comment cm inner join " +
            "users u1 on cm.uid=u1.user_id INNER JOIN users u2 on cm.pid=u2.user_id  where dj_id =${id}")
    List<Comment> selectChildComment(String id);




    /**
     * 查询所有评论
     * @param id
     * @return
     */
    @Results({
            @Result( id = true,column = "id",property = "id"),
            @Result( column = "id",property = "commentList",
                    many = @Many(select = "com.example.yjhuser.mapper.CommentMapper.selectChildComment")),
    })
    @Select("select u1.`name` pname,u2.name name,u2.image, cm.* from users u1 right JOIN `comment` cm on u1.user_id = cm.pid\n" +
            " left JOIN users u2 on u2.user_id=cm.uid\n" +
            " where cm.type=${type} and dj_id=0 and top_id=${id}")
    List<Comment> selectAllComment(@Param("id") String id,@Param("type") String type);







    @Select("select *  from (select cmm.*,video.title,video.image, NULL AS ctt from `comment` cmm inner join  video on top_id=video.id where cmm.type=1  UNION ALL\n" +
            "         select cmm.*,tiezi.title ,tiezi.image,tiezi.content ctt from `comment` cmm inner join  tiezi on top_id=tiezi.id where cmm.type=2) att where att.uid=1")
    List<PersonCommentDTO> selectAllCommentByUserId(@Param("id") String id);
}
